home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / macintosh technotes and q&as / technotes / tn / rd_1077.hqx / Routine Descriptors in lib / DemoLibGlue.c < prev   
Encoding:
C/C++ Source or Header  |  1996-09-09  |  2.3 KB  |  84 lines

  1. #include <CodeFragments.h>
  2. #include "DemoLib.h"
  3.  
  4. static OSErr Setup_UPP(UniversalProcPtr* pUPP,Str255 pSymName);
  5. static pascal OSErr GetSystemArchitecture(OSType *archType);
  6.  
  7. // Private functions
  8.  
  9. static OSErr Setup_UPP(UniversalProcPtr* pUPP,Str255 pSymName)
  10. {
  11.     static CFragConnectionID    gConnectionID = 0;
  12.     static OSType sArchType = kAnyCFragArch;
  13.     Str255                tLibName;
  14.     ProcPtr                tSymbolAddr;
  15.     OSErr                 myErr = noErr;
  16.     unsigned char        tSymClass;
  17.  
  18.     if (sArchType == kAnyCFragArch)                // if architecture is still undefined…
  19.     {
  20.         gConnectionID = 0;                                // …force (re)connect to library
  21.         myErr = GetSystemArchitecture(&sArchType);    // & determine current atchitecture.
  22.         if (myErr != noErr)
  23.             return myErr;
  24.     }
  25.  
  26.     if (*pUPP == 0)
  27.     {
  28.         if (gConnectionID == 0)
  29.             myErr = GetSharedLibrary("\pDemoLibrary",sArchType,kLoadLib,
  30.                 &gConnectionID,(Ptr *) &tSymbolAddr,tLibName);
  31.         if (myErr == noErr)
  32.             myErr = FindSymbol(gConnectionID,pSymName,(Ptr *) pUPP, &tSymClass);
  33.     }
  34.     return myErr;
  35. }
  36.  
  37. static pascal OSErr GetSystemArchitecture(OSType *archType)
  38. {
  39.     static long sSysArchitecture = 0;    // static so we only Gestalt the first time
  40.     OSErr    tOSErr = noErr;
  41.  
  42.     *archType = kAnyCFragArch;            // assume wild architecture
  43.  
  44.     // If we don't know the system architecture yet…
  45.     if (sSysArchitecture == 0)
  46.         // …Ask Gestalt what kind of machine we are running on.
  47.         tOSErr = Gestalt(gestaltSysArchitecture, &sSysArchitecture);
  48.  
  49.     if (tOSErr == noErr)    // if no errors
  50.     {
  51.         if (sSysArchitecture == gestalt68k)                // 68k?
  52.             *archType = kMotorola68KArch;
  53.         else if (sSysArchitecture == gestaltPowerPC)    // PPC?
  54.             *archType = kPowerPCArch;
  55.         else
  56.             tOSErr = gestaltUnknownErr;                    // who knows what might be next?
  57.     }
  58.     return tOSErr;
  59. }
  60.  
  61. // Public functions
  62.  
  63. pascal void Do_Demo(void)
  64. {
  65.     static UniversalProcPtr    tDo_Demo_UPP = 0;
  66.     if (noErr == Setup_UPP(&tDo_Demo_UPP,"\pDo_DemoRD"))
  67.         ((Do_DemoProcPtr)(tDo_Demo_UPP))();
  68. }
  69.  
  70. pascal void Set_DemoValue(long pLong)
  71. {
  72.     static UniversalProcPtr    tSet_DemoValue_UPP = 0;
  73.     if (noErr == Setup_UPP(&tSet_DemoValue_UPP,"\pSet_DemoValueRD"))
  74.         ((Set_DemoValueProcPtr)(tSet_DemoValue_UPP))(pLong);
  75. }
  76. pascal long Get_DemoValue(void)
  77. {
  78.     static UniversalProcPtr    tGet_DemoValue_UPP = 0;
  79.     if (noErr == Setup_UPP(&tGet_DemoValue_UPP,"\pGet_DemoValueRD"))
  80.         return ((Get_DemoValueProcPtr)(tGet_DemoValue_UPP))();
  81.     else
  82.         return 0;
  83. }
  84.